//
//  DefaultChooseView.m
//  AnnCar_user
//
//  Created by LiBenCan on 17/10/25.
//  Copyright © 2017年 LiBenCan. All rights reserved.
//

#import "DefaultChooseView.h"
#import "chooseBtnView.h"
@implementation DefaultChooseView

//默认选择
- (instancetype)initWithFrame:(CGRect)frame IsSelect:(BOOL)isSelect
{
    if (self = [super initWithFrame:frame]) {
        self.userInteractionEnabled = YES;
        
        _defaultBTn = [[chooseBtnView alloc]initWithFrame:CGRectMake(0, 0, SCREENW/3, 50*screenW_6) Title:@"设为默认" NomolImageV:@"circle" SelectImageV:@"circle_select" IsSelect:isSelect];
        [self addSubview:_defaultBTn];
        
        _editBtn = [[chooseBtnView alloc]initWithFrame:CGRectMake(SCREENW-165*screenW_6, 0,60*screenW_6, 50*screenW_6) Title:@"编辑" NomolImageV:@"My_edit" SelectImageV:@"My_edit" IsSelect:NO];
        [self addSubview:_editBtn];
        
        _delettBtn = [[chooseBtnView alloc]initWithFrame:CGRectMake(SCREENW-90*screenW_6,0,75*screenW_6,50*screenW_6) Title:@"删除" NomolImageV:@"My_delete" SelectImageV:@"My_delete" IsSelect:NO];
        [self addSubview:_delettBtn];
        
        //给各按钮添加点击事件
        UITapGestureRecognizer *defaultTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(chooseTap:)];
        UITapGestureRecognizer *editTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(chooseTap:)];
        UITapGestureRecognizer *deleteTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(chooseTap:)];
        [_defaultBTn addGestureRecognizer:defaultTap];
        [_editBtn addGestureRecognizer:editTap];
        [_delettBtn addGestureRecognizer:deleteTap];
        
    }
    return self;
}

//按钮的点击事件
-(void)chooseTap:(UITapGestureRecognizer *)tap
{
   
    if (_selectBlock) {
         chooseBtnView *chooseBtn = (id)tap.view;
        if ([chooseBtn.titleLab.text isEqualToString:@"设为默认"]) {
            self.selectBlock(0);
        }else if ([chooseBtn.titleLab.text isEqualToString:@"编辑"])
        {
             self.selectBlock(1);
        }else if ([chooseBtn.titleLab.text isEqualToString:@"删除"])
        {
             self.selectBlock(2);
        }
    }
}
@end
